﻿$(document).ready(function() {
    var array = [];
    var links = $("a");

    var link, http, local, gtri, excel, word, powerpoint, pdf;

    var sameDomain;

    var currentPage = document.URL.toLowerCase();

    var beginDomain = currentPage.indexOf("://");
    var endDomain = currentPage.indexOf("/", beginDomain + 3);

    var currentDomain = currentPage.substring(beginDomain, endDomain);

    for (var i = 0; i < links.length; i++) {

        if (links[i].href == "") {
            continue;
        }

        link = links[i].href.toLowerCase();

        sameDomain = link.indexOf(currentDomain);

        excel = (new RegExp("\.xlsx?"));
        word = (new RegExp("\.docx?"));
        powerpoint = (new RegExp("\.pptx?"));
        pdf = (new RegExp("\.pdf"));

        if (pdf.test(link)) {
            links[i].innerHTML = links[i].innerHTML + "<img src='" + ROOT + "Content/images/pdf.png' class='droppx'/>";
        }
        else if (word.test(link)) {
            links[i].innerHTML = links[i].innerHTML + "<img src='" + ROOT + "Content/images/doc.png' class='droppx'/>";
        }
        else if (excel.test(link)) {
            links[i].innerHTML = links[i].innerHTML + "<img src='" + ROOT + "Content/images/xls.png' class='droppx'/>";
        }
        else if (powerpoint.test(link)) {
            links[i].innerHTML = links[i].innerHTML + "<img src='" + ROOT + "Content/images/ppt.png' class='droppx'/>";
        }
        else if (sameDomain == -1) {
            links[i].target = "_blank";
            links[i].innerHTML = links[i].innerHTML + "<img src='" + ROOT + "Content/images/external.png' class='droppx'/>";
        }

    }
});